<?php
/**
 * Created by PhpStorm.
 * User: chenhaibin
 * Date: 17/8/5
 * Time: 下午8:45
 */

namespace app\common\logic;

class DistributLogic
{
    public function rebate_log($order){

        //自己不是合伙人或者购买人没有上级，就不分销
        if(M('users')->where('user_id',$order['user_id'])->getField('is_distribut') == '1') {
            $user_id = $order['user_id'];
        }else{
            $user_id =  M('users')->where('user_id',$order['user_id'])->getField('first_leader');
        }
        if($user_id){
            $userInfo = M('users')->where('user_id',$user_id)->find();
            $data = array(
                'user_id'           => $user_id, // 获佣用户
                'buy_user_id'       => $order['user_id'], // 购买人id
                'nickname'          => $userInfo['nickname'], // 购买人名称
                'order_sn'          => $order['order_sn'],//订单编号,
                'order_id'          => $order['order_id'],//订单id,
                'goods_price'       => $order['goods_price'],//订单商品总额,
                'money'             => $order['goods_price']*$userInfo['distribution_value']/100,//获佣金额,
                'level'             => $userInfo['level'],//获佣用户级别,
                'create_time'       => time(),//分成记录生成时间,
//                'confirm'           => ,//确定收货时间,
                'status'            => 0,//0未付款,1已付款, 2等待分成(已收货) 3已分成, 4已取消,
//                'confirm_time'      => ,//确定分成或者取消时间
//                'remark'            => ,//如果是取消, 有取消备注
            );
            M("rebate_log")->add($data);
        }
    }
}
